home *** CD-ROM | disk | FTP | other *** search
- Path: user1.mnsinc.com!huang
- From: huang@mnsinc.com (Szu-Wen Huang)
- Newsgroups: comp.lang.c,comp.std.c,finet.atk.kielet.c
- Subject: Re: TYPEDEF and Watcom C++ 10.5
- Followup-To: comp.lang.c,comp.std.c,finet.atk.kielet.c
- Date: 1 Apr 1996 14:15:26 GMT
- Organization: Monumental Network Systems
- Distribution: world
- Message-ID: <4joodu$m9p@news1.mnsinc.com>
- References: <4jlu1r$cs7@nic.dataphone.se>
- NNTP-Posting-Host: user1.mnsinc.com
- X-Newsreader: TIN [version 1.2 PL2]
-
- Jarmo Paavilainen (skorpio@dataphone.se) wrote:
-
- : typedef struct
- : {
- : WORD CheckSum;
- : WORD Version;
- : BYTE PatchLevel;
- : BYTE Name[21];
- : WORD MarkerVersion;
- : }VERSION_TAG_STRUCT;
-
- : Shouldn't sizeof(VERSION_TAG_STRUCT) always result in 28. By other words
- : shouldn't WORD always be 16 bits and BYTE 8 bits.
-
- : If so why does my compiler claim that sizeof(VERSION_TAG_STRUCT) == 34.
- : All this in 32 bit OS/2 PM and Watcom C++ 10.5
-
- You show two misconceptions. First of all, C guarantees you a minimum
- number of bits you can use for each type, but does not guarantee that your
- compiler will not give you more. Secondly, even if the additive size of
- each field in a struct is a certain number of bytes, the compiler is still
- free to pad the structure (usually to align to word boundaries), or to
- optimize for speed. Let me answer your last question with another
- question: Why do you think sizeof() is provided if you can count on the
- structure being 28 bytes? ;)
-